# coding:utf-8

import sys
sys.path.append('../')
#sys.path.append('%s/../../' % os.getcwd())

from core.Item import *
from recommender.Evaluate import *

# TESTS

# test 1: inversely proportional relevance=100 min=0 max=100 proportional=False
criteriaList = [{'attr':'price', 'min':0, 'max':100, 'relevance':100, 'proportional':False}]

i1 = Item(1,[{'attr':'price', 'value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'price', 'value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getEvaluation('price')==50.0 and newItemList[1].getEvaluation('price')==75.0: print 'test 1 ok'
else: print "test 1 error!!!!!!!!!!!"

# test 2: inversely proportional relevance=50 min=0 max=100 proportional=False
criteriaList = [{'attr':'price', 'min':0, 'max':100, 'relevance':50, 'proportional':False}]

i1 = Item(1,[{'attr':'price', 'value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'price', 'value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getEvaluation('price')==25.0 and newItemList[1].getEvaluation('price')==37.5: print 'test 2 ok'
else: print "test 2 error!!!!!!!!!!!"
 
 
 
 
    
# test 3: directly proportional relevance=100 min=0 max=100 proportional=True
criteriaList = [{'attr':'reputation', 'min':0, 'max':100, 'relevance':100, 'proportional':True}]

i1 = Item(1,[{'attr':'reputation', 'value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'reputation', 'value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getEvaluation('reputation')==50.0 and newItemList[1].getEvaluation('reputation')==25.0: print 'test 3 ok'
else: print "test 3 error!!!!!!!!!!!"
      
# test 4: directly proportional relevance=50 min=0 max=100 proportional=True
criteriaList = [{'attr':'reputation', 'min':0, 'max':100, 'relevance':50, 'proportional':True}]

i1 = Item(1,[{'attr':'reputation', 'value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'reputation', 'value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getEvaluation('reputation')==25.0 and newItemList[1].getEvaluation('reputation')==12.5: print 'test 4 ok'
else: print "test 4 error!!!!!!!!!!!"


# test 5: multicriteria evaluation => with same relevance index
#    criteria 1: inversely proportional relevance=100 min=0 max=100 proportional=False
#    criteria 2: directly proportional relevance=100 min=0 max=100 proportional=True
criteriaList = [{'attr':'price', 'min':0, 'max':100, 'relevance':100, 'proportional':False},
                {'attr':'reputation', 'min':0, 'max':100, 'relevance':100, 'proportional':True}]

i1 = Item(1,[{'attr':'price','value':50.0, 'evaluation':None}, {'attr':'reputation','value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'price', 'value':25.0, 'evaluation':None}, {'attr':'reputation','value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getFinalEvaluation()==100.0 and newItemList[1].getFinalEvaluation()==100.0: print 'test 5 ok'

# test 6: multicriteria evaluation => with different relevance index
#    criteria 1: inversely proportional relevance=100 min=0 max=100 proportional=False
#    criteria 2: directly proportional relevance=50 min=0 max=100 proportional=True
criteriaList = [{'attr':'price', 'min':0, 'max':100, 'relevance':100, 'proportional':False},
                {'attr':'reputation', 'min':0, 'max':100, 'relevance':50, 'proportional':True}]

i1 = Item(1,[{'attr':'price','value':50.0, 'evaluation':None}, {'attr':'reputation','value':50.0, 'evaluation':None}])
i2 = Item(2,[{'attr':'price', 'value':25.0, 'evaluation':None}, {'attr':'reputation','value':25.0, 'evaluation':None}])
itemList = [i1,i2]

newItemList = Evaluate.evaluate(itemList, criteriaList)
print "Final evaluation:", newItemList[0].getFinalEvaluation(), newItemList[1].getFinalEvaluation()
if newItemList[0].getFinalEvaluation()==75.0 and newItemList[1].getFinalEvaluation()==87.5: print 'test 6 ok'
else: print "test 6 error!!!!!!!!!!!"